package cn.fbs.controller;

import cn.fbs.model.TDataInfo;
import cn.fbs.param.Params;
import cn.fbs.service.DataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "资料模块")
@RestController
@RequestMapping("data")
public class DataController {
    @Autowired
    private DataService dataService;

    @ApiOperation("查询所有的资料")
    @GetMapping("findAll")
    public List<TDataInfo> findAll()   { System.out.println("findAll");
        return dataService.findAll();
    }

    @ApiOperation("新增资料")
    @PostMapping("add")
    public void insert(@RequestBody @ApiParam("资料实体") TDataInfo tDataInfo) {
         System.out.println("insert");
        dataService.insert(tDataInfo);
    }

    @ApiOperation("更新资料")
    @PostMapping("update")
    public void update(@RequestBody @ApiParam("资料实体") TDataInfo tDataInfo) {
         System.out.println("update");
        dataService.update(tDataInfo);
    }

    @ApiOperation("根据id删除资料")
    @PostMapping("delete")
    public void delete(@RequestBody() @ApiParam(name = "id", value = "主键") Params params ) {
         System.out.println("delete");
        dataService.delete(params.getId().longValue());
    }

    @ApiOperation("根据id查询资料")
    @ApiImplicitParam(name = "id", value = "资料Id")
    @GetMapping("get")
    public TDataInfo get(Long id) {
         System.out.println("get");  return dataService.selectByPrimaryKey(id);
    }

    @ApiOperation("根据资料名词模糊查询资料")
    @ApiImplicitParam(name = "fileName", value = "资料名称")
    @GetMapping("search")
    public List<TDataInfo> likeQuery(String fileName) { System.out.println("likeQuery");
        return dataService.likeQuery(fileName);
    }


}
